package com.cneiu.ppms.web.action;

import com.cneiu.ppms.web.base.BaseController;
import com.cneiu.ppms.web.model.PowerPlantModel;
import com.cneiu.ppms.web.service.PowerPlantService;
import com.jfinal.plugin.activerecord.Page;
/**
 * 电厂Controller
 * @author zhaokf
 * @date 2013-04-19
 */
public class PowerPlantController extends BaseController{
	/**
	 * 获取page limit得到电厂列表(已测试)
	 */
	public void list(){
		Page<PowerPlantModel> PP = PowerPlantService.list(this.getParams());
		if (null != PP){
			renderGrid(PP.getTotalRow(), PP.getList());
		}else{
			renderAjax(false, PowerPlantService.getError());
		}
	}
	
	/**
	 * 根据ID查询电厂(已测试)
	 */
	public void get(){
		try{
			PowerPlantModel model = PowerPlantService.get(this.getParams());
			renderGrid(model);
		}catch (Exception e){
			e.printStackTrace();
		}
	}
	

	/**
	 * 添加电厂(已测试)
	 */
	public void add(){
		try{
			if(!PowerPlantService.isAdd(this.getParams())){
				renderAjax(false, PowerPlantService.getError());
			}else{
				renderAjax(true, "添加电厂成功");
			}
		}
		catch (Exception e){
			e.printStackTrace();
		}
	}

	/**
	 * 编辑电厂(已测试)
	 */
	public void edit(){
		try{
			if(!PowerPlantService.isUpdate(this.getParams())){
				renderAjax(false, PowerPlantService.getError());
			}else{
				renderAjax(true, "编辑电厂成功");
			}
		}catch (Exception e){
			e.printStackTrace();
		}
	}
	
	/**
	 * 删除电厂(已测试)
	 */
	public void delete(){
		try{
			if(!PowerPlantService.isDelete(this.getParams())){
				renderAjax(false, PowerPlantService.getError());
			}else{
				renderAjax(true, "删除电厂成功");
			}
		}catch (Exception e){
			e.printStackTrace();
		}
	}
}
